package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.order.OrderAndItems;
import com.qingcheng.pojo.order.OrderStatistics;
import com.qingcheng.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    @GetMapping("/findAll")
    public List<Order> findAll() {
        return orderService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size) {
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String, Object> searchMap) {
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String, Object> searchMap, int page, int size) {
        return orderService.findPage(searchMap, page, size);
    }

    @GetMapping("/findById")
    public Order findById(String id) {
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order) {
        orderService.add(order);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order) {
        orderService.update(order);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(String id) {
        orderService.delete(id);
        return new Result();
    }

    /**
     * 查询订单和订单明细
     * @param id
     * @return
     */
    @GetMapping("/findOrderAndItemsById")
    public OrderAndItems findOrderAndItemsById(String id) {
        return orderService.findOrderAndItemsById(id);
    }

    /**
     * 根据ID查询未发货order
     * @param consignStatus
     * @param ids
     * @return
     */
    @PostMapping("/noConsing")
    public List<Order> unConsign(@RequestBody String consignStatus,int[] ids) {
        return orderService.unConsign(consignStatus,ids);
    }

    /**
     * 发货
     * @param orders
     * @return
     */
    @PostMapping("/batchSend")
    public Result batchSend(@RequestBody List<Order> orders){
        orderService.batchSend(orders);
        return new Result();
    }

    /**
     * 合并订单
     * @param id1
     * @param id2
     * @return
     */
    @GetMapping("/mergeOrder")
    public Result mergeOrder(String id1,String id2){
        orderService.mergeOrder(id1,id2);
        return new Result();
    }

    @PostMapping("/splitOrder")
    public Result splitOrder(@RequestBody List<Map> itemList){

        return new Result();
    }

    @RequestMapping("/test00")
    public void test0(){
        orderService.test00();
    }

}
